home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_005 / printer / printer.c next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  123 lines

  1. /*
  2.  *
  3.  *    DISCLAIMER:
  4.  *
  5.  *    This program is provided as a service to the programmer
  6.  *    community to demonstrate one or more features of the Amiga
  7.  *    personal computer.  These code samples may be freely used
  8.  *    for commercial or noncommercial purposes.
  9.  * 
  10.  *     Commodore Electronics, Ltd ("Commodore") makes no
  11.  *    warranties, either expressed or implied, with respect
  12.  *    to the program described herein, its quality, performance,
  13.  *    merchantability, or fitness for any particular purpose.
  14.  *    This program is provided "as is" and the entire risk
  15.  *    as to its quality and performance is with the user.
  16.  *    Should the program prove defective following its
  17.  *    purchase, the user (and not the creator of the program,
  18.  *    Commodore, their distributors or their retailers)
  19.  *    assumes the entire cost of all necessary damages.  In 
  20.  *    no event will Commodore be liable for direct, indirect,
  21.  *    incidental or consequential damages resulting from any
  22.  *    defect in the program even if it has been advised of the 
  23.  *    possibility of such damages.  Some laws do not allow
  24.  *    the exclusion or limitation of implied warranties or
  25.  *    liabilities for incidental or consequential damages,
  26.  *    so the above limitation or exclusion may not apply.
  27.  *
  28.  */
  29.  
  30. /* printer.c - program to do a raster dump to whatever printer is specified
  31.  *         by Preferences, of the Workbench Screen.  
  32.  *
  33.  * Author:  Rob Peck, 12/1/85
  34.  *
  35.  * This code may be freely utilized to develop programs for the Amiga
  36.  */
  37.  
  38.  
  39. #include "exec/types.h"
  40. #include "intuition/intuition.h"
  41. #include "devices/printer.h"
  42. #define INTUITION_WONT_OPEN 1000
  43.  
  44. union printerIO {
  45.        struct IOStdReq ios;
  46.        struct IODRPReq iodrp;
  47.        struct IOPrtCmdReq iopc;
  48.        };
  49.  
  50. union printerIO *request;    /* a pointer to a request block */
  51. extern int DumpRPort();
  52. extern struct IORequest *CreateExtIO();
  53. extern struct Window *OpenWindow();
  54. extern struct Port *CreatePort();
  55. struct IntuitionBase *IntuitionBase;
  56.  
  57. struct NewWindow nw = {
  58.         0, 0, 100, 40, 0, 1, 0, 0, NULL, NULL, NULL, NULL, NULL,
  59.         0, 0, 0, 0, WBENCHSCREEN
  60.         };
  61.          
  62. main()
  63. {
  64.         struct Window *w;
  65.         struct Screen *screen;
  66.         struct RastPort *rp;
  67.         struct ViewPort *vp;
  68.         struct ColorMap *cm;
  69.     union printerIO sizeDummy;
  70.         int modes,width,height,error;
  71.         struct Port *printerPort;      /* at which to receive reply */
  72.         IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  73.                         "intuition.library", 0);
  74.         if (IntuitionBase == NULL) exit(INTUITION_WONT_OPEN);
  75.  
  76.         w = OpenWindow(&nw);
  77.         if(w == NULL) goto cleanup1;
  78.         screen = w->WScreen;    /* get screen address from window */
  79.         CloseWindow(w);         /* once have screen address, no
  80.                                  * more need for window, close it.
  81.                                  */
  82.         vp = &screen->ViewPort; /* get screen's ViewPort, from
  83.                                  * which the colormap will be gotten */
  84.         rp = &screen->RastPort; /* get screen's RastPort, which
  85.                                  * is what gets dumped to printer */
  86.         
  87.         cm = vp->ColorMap;      /* retrieve pointer to colormap for
  88.                                  * the printer dump */
  89.         modes = vp->Modes;      /* retrieve the modes variable */
  90.         width = vp->DWidth;     /* retrieve width to print */
  91.         height = vp->DHeight;   /* retrieve height to print */
  92.  
  93.         printerPort = CreatePort("my.print.port",0);
  94.         request =  (union printerIO *)CreateExtIO(printerPort,
  95.                                         sizeof(sizeDummy));
  96.  
  97.         error = OpenPrinter(request);
  98.         if(error != 0) goto cleanup2;
  99.  
  100.     Delay(300);    /* 300/60 = 6 seconds delay before it starts */
  101.         error = DumpRPort(
  102.                         request,/* pointer to initialized request */
  103.                         rp,     /* rastport pointer */
  104.                         cm,     /* color map pointer */
  105.                         modes,  /* low, high res, etc (display modes)*/
  106.                         0, 0,   /* x and y offsets into rastport */
  107.                         width,height, /* source size */
  108.                         width,(height * 2), /* dest rows, columns */
  109.                         SPECIAL_FULLROWS 
  110.             | SPECIAL_FULLCOLS
  111.             | SPECIAL_ASPECT /* io Special value, says print
  112.                                  * as pixels only, direct copy */
  113.                         );
  114.         ClosePrinter(request);
  115. cleanup2:
  116.         DeleteExtIO(request, sizeof(sizeDummy));
  117.         DeletePort(printerPort);
  118. cleanup1:
  119.         CloseLibrary(IntuitionBase);
  120.         
  121. }               /* end of demo screen dump */
  122.  
  123.